还是sql急``

来源:百度知道 编辑:UC知道 时间:2024/05/05 15:14:29
怎么样把这样一个表
year month amonunt
1991 1 1.1
1991 2 1.2
1991 3 1.3
1991 4 1.4
1992 1 2.1
1992 2 2.2
1992 3 2.3
1992 4 2.4
查成这样一个结果,排列如下:
year m1 m2 m3 m4
1991 1.1 1.2 1.3 1.4
1992 2.1 2.2 2.3 2.4

select t.year,t1.amonunt as m1,t2.amonunt as m2,t3.amonunt as m3,t4.amonunt as m4 from table t,table t1,table t2,table t3,table t4 where t.year=t1.year and t.year=t2.year and t.year=t3.year and t.year=t4.year and t1.month=1 and t2.month=2 and t3.month=3 and t4.month=4

^-^!敲得我累死了

果然是累死了,竟然少敲了一个distinct,应该是:
select distinct t.year,t1.amonunt as m1,t2.amonunt as m2,t3.amonunt as m3,t4.amonunt as m4 from table t,table t1,table t2,table t3,table t4 where t.year=t1.year and t.year=t2.year and t.year=t3.year and t.year=t4.year and t1.month=1 and t2.month=2 and t3.month=3 and t4.month=4